package com.imooc.security.browser;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.actuate.autoconfigure.ShellProperties;
import org.springframework.security.core.authority.AuthorityUtils;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Component;

/**
 * @author :xie
 * Email: 1487471733@qq.com
 * Date: 2018/7/14
 * Time: 16:36
 * Describe:
 */
@Component
public class MyUserDetailsServcice implements UserDetailsService {

    private Logger logger =LoggerFactory.getLogger(getClass());

    @Autowired
    private PasswordEncoder passwordEncoder;

    @Override
    public UserDetails loadUserByUsername(String usrename) throws UsernameNotFoundException {
        logger.info("登陆用户："+usrename);
        boolean ax=true;
        String password=passwordEncoder.encode("123456");
        return new User(usrename,password,
                ax,ax,ax,ax,
                AuthorityUtils.commaSeparatedStringToAuthorityList("admin"));
    }
}
